package com.albaba.designpattern.factory.text_001.controller;

import com.albaba.designpattern.factory.text_001.entity.AwardInfo;
import com.albaba.designpattern.factory.text_001.entity.DiscountResult;
import com.albaba.designpattern.factory.text_001.entity.SmallGiftInfo;
import com.albaba.designpattern.factory.text_001.service.DiscountService;
import com.albaba.designpattern.factory.text_001.service.SmallGiftService;
import com.albaba.designpattern.factory.text_001.service.YouKuMemberService;

import java.util.Locale;
import java.util.UUID;

/**
 * @Description: 发放奖品
 * @Author zx
 * @Date 2025/2/19 10:46
 * @Version 1.0
 */
public class DeliverController {

    /**
     * 按照类型的不同发放奖品 (奖品类型 1 打折券, 2 优酷会员, 3 小礼品)
     * @param awardInfo
     */
    public static void awardToUser(AwardInfo awardInfo) {
        if ("1".equals(awardInfo.getAwardTypes())) {
            DiscountService discountService = new DiscountService();
            DiscountResult discountResult = discountService.sendDiscount(awardInfo.getUid(), awardInfo.getAwardNumber());
            System.out.println("发放打折券成功" + discountResult);
        } else if ("2".equals(awardInfo.getAwardTypes())) {
            YouKuMemberService youKuMemberService = new YouKuMemberService();
            youKuMemberService.openMember(awardInfo.getExtMap().get("phone"), awardInfo.getAwardNumber());
            System.out.println("发放优酷会员成功");
        } else if ("3".equals(awardInfo.getAwardTypes())) {
            SmallGiftInfo smallGiftInfo = new SmallGiftInfo();
            smallGiftInfo.setUserName(awardInfo.getExtMap().get("userName"));
            smallGiftInfo.setAddress(awardInfo.getExtMap().get("address"));
            smallGiftInfo.setOrderId(UUID.randomUUID().toString());
            smallGiftInfo.setUserPhone(awardInfo.getExtMap().get("phone"));

            SmallGiftService smallGiftService = new SmallGiftService();
            if (smallGiftService.giveSmallGift(smallGiftInfo)) {
                System.out.println("发放小礼品成功");
            }
        }
    }

    public static void main(String[] args) {
        AwardInfo awardInfo = new AwardInfo();
        awardInfo.setAwardTypes("1");
        awardInfo.setUid(UUID.randomUUID().toString());
        awardInfo.setAwardNumber("MD23532");

        awardToUser(awardInfo);
    }
}
